{include file='common/head'}
<body>
<div class="x-body">
    <form class="layui-form" method="post" enctype="multipart/form-data">
        <input type="hidden" value="<?php echo $rs['zid']?>" name="id">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="gname" name="gname" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="<?php echo $rs['gname']?>">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>手机号码
            </label>
            <div class="layui-input-inline">
                <input type="text" id="phone" name="phone"  lay-verify="phone"
                       autocomplete="off" class="layui-input" value="<?php echo $rs['phone']?>">
            </div>
        </div>
		<div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>角色
            </label> 
            <div class="layui-input-inline">
                <select name="jid" id="jname"  style="width:96px; " >
				<option value="<?php echo $rs['gid']?>"><?php echo $rs['jname']?></option>
                    {volist name='jiao' id='jiao'}
				 <option value="{$jiao.id}">{$jiao.jname}</option>
                    {/volist}
                </select>
            </div>
        </div>
		<div>
            <div >
                <input type="hidden" id="hid">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
               提交
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;
        //自定义验证规则
        //监听提交
        form.on('submit(add)', function(data){
            //console.log(data);
            //alert($('#id').val());
            var url="";
            $.ajax({
                type: "post",
                async:false,
                url: "{:url('admin/guanli/update')}",
                data: data.field,
                dataType:'json',
                success:function (res) {
                    /*layer.msg('添加成功！');
                    setTimeout(function () {
                        location.reload();
                    }, 1000);*/
                    //发异步，把数据提交给php
                    if(res==1)
                    {
                        layer.msg("修改成功！",{icon: 6},function () {
                            //获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            window.parent.location.reload();//刷新父级窗口

                        });
                        return false;
                    }
                    else
                    {
                        layer.msg("修改失败！",{icon: 5},function () {
                            //获得frame索引
                            /*var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            window.parent.location.reload();//刷新父级窗口*/
                        });
                        return false;
                    }

                }
            })
            return false;
        });

    });
</script>
<script>
    layui.use('upload', function() {
        var upload = layui.upload;
        var $ = layui.jquery;
        var uploadInst = upload.render({
            elem:'#cover'
            ,url:'{:url("admin/guanli/doUpload")}'
            ,multiple: 'false'
            ,accept:'images'  // 允许上传的文件类型
            ,auto:true // 自动上传
            ,before:function (obj) {
                //console.log(obj);
                // 预览
                obj.preview(function(index,file,result) {
                    // console.log(file.name);    //图片名字
                    // console.log(file.type);    //图片格式
                    // console.log(file.size);    //图片大小
                    // console.log(result);       //图片地址
                    $('#preview').append('<img src="' + result + '" alt="' + file.name +
                        '" class="layui-upload-img" style="width:80%;objec-fit: cover;;margin-left:10px">')
                    // $('#preview').attr('src',result); //图片链接 base64

                });
                // layer.load();
            }
            // 上传成功回调
            ,done:function(res) {
                // console.log(upload);
                // console.log(res);
                if (res.code == 1) {
                    $('#picture').val($('#picture').val()+res.url);//alert( $('#picture').val());
                    return layer.msg(res.msg);
                }
                return layer.msg(res.msg);
            }
            // 上传失败回调
            ,error:function(index,upload) {
                return layer.msg(res.msg);
            }
        });
    });
</script>
</body>

</html>